package com.ebt.m.data.entity;

import java.io.Serializable;
import java.util.List;

/**
 * 合计
 * 
 * @author Michael.li
 * 
 */
public abstract class SummationInfo implements Serializable
{
	/**
	 * 
	 */
	private static final long serialVersionUID = -3464780968613005431L;
	public int Id;
	public int Count;
	public boolean IsShow;

	/**
	 * 
	 * @param list
	 * @return
	 */
	public static int getSum(List<? extends SummationInfo> list)
	{
		if (list == null)
			return 0;
		int count = 0;
		for (SummationInfo info : list) {
			count += info.Count;
		}
		return count;
	}

	/**
	 * 获取特定id在列表中的位置，如果对应的IsShow是true，则返回该位置，反之则为-1
	 * 
	 * @param list
	 * @param id
	 * @return
	 */
	public static int getPositionWithShow(List<? extends SummationInfo> list, int id)
	{
		int position = -1;
		for (int i = 0, j = list.size(); i < j; i++) {
			SummationInfo info = list.get(i);
			if (info.Id == id) {
				if (info.IsShow) {
					position = i;
				}
				break;
			}
		}
		return position;
	}

	/**
	 * 获取特定id在列表中的位置
	 * 
	 * @param list
	 * @param id
	 * @return
	 */
	public static int getPosition(List<? extends SummationInfo> list, long id)
	{
		int position = 0;
		for (int i = 0, j = list.size(); i < j; i++) {
			SummationInfo info = list.get(i);
			if (info.Id == id) {
				position = i;
				break;
			}
		}
		return position;
	}
}
